package com.splant.android.smart.LogLevel;

import android.os.Environment;

import java.io.File;
import java.io.FileOutputStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by Administrator on 2017/6/13.
 */

public class FileLog {

    private static DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
    public static void log(String errDatas)
    {
        try
        {
            StringBuffer sb = new StringBuffer();
            sb.append(errDatas);
            long timestamp = System.currentTimeMillis();
            String time = formatter.format(new Date());
            String fileName = "crash-" + time + "-" + timestamp + ".log";
            if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
                String path = "/sdcard/crash/";
                File dir = new File(path);
                if (!dir.exists()) {
                    dir.mkdirs();
                }
                FileOutputStream fos = new FileOutputStream(path + fileName);
                fos.write(sb.toString().getBytes());
                fos.close();
            }

        }
        catch (Exception e) {

        }
    }
}
